﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;

using CoolCode.Entities;
using CoolCode.Services;
using CoolCode.Web;
using CoolCode.Linq;
using CoolCode.WebServices;

namespace CoolCode.Web.UI.WebServices
{
    /// <summary>
    /// Summary description for $codebehindclassname$
    /// </summary>
    //[WebService(Namespace = "http://tempuri.org/")]
    //[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class ProductHandler : IHttpHandler
    {
        public void ProcessRequest(HttpContext context)
        {
            string key = RequestUtility.GetQueryString("key");
            if (string.IsNullOrEmpty(key))
            {
                //context.Response.Write("无效操作!");
                //context.Response.End();
                this.Warning("无效操作!");
            }

            key = key.Trim();
            // string template = Utility.GetMapPath("~/Content/excel/Template.xls");
            //string fileName = key + ".xls";
            //string savePath = Path.Combine(Utility.GetMapPath("~/Output/"), fileName);

            ExportService service = new ExportService();
            ExportResult message;
            string savePath = service.ExportOutbound(new Guid(key), out message);
            if (message != ExportResult.Success && message != ExportResult.FileExist)
            {
                context.Response.Write(message.GetAttachedString());
                context.Response.End();
            }

            this.WriteFile(FileType.Excel, savePath);
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}
